﻿using CommunityToolkit.Mvvm.ComponentModel;
using MG.SmartHMI.Common;
using MG.SmartHMI.Domain;
using MG.SmartHMI.Entity.DAO;
using MG.Util.Log;
using SqlSugar.Extensions;

namespace MG.SmartHMI.Model
{
    public partial class InputSignalViewModel : BaseItemsControl
    {
        public InputSignalViewModel(RegisterConfig data) : base(data)
        {
        }

        public InputSignalViewModel() : base()
        {
        }

        #region Input Signal

        [ObservableProperty]
        private bool inputSignal;

        public override void UpdateRead()
        {
            InputSignal = ModbusCtrl.Instance.UnitRead(RegisterData.DataType, RegisterData.Address).Content.ObjToBool();
            EventBus.Default.Log(new LogInfo($"读取 [{RegisterData.Address}]  值 [{InputSignal}]", LogLevel.Trace));
        }


        public override void ParsebyBatchData(ref byte[] data, ref bool[] bdata)
        {
            InputSignal = ModbusCtrl.Instance.ParseBatchBoolData(ref bdata, int.Parse(RegisterData.Address));
        }

        #endregion Input Signal
    }
}